import com.googlecode.easyec.cache.CacheProvider;
import com.googlecode.easyec.cache.CacheStatus;
import org.junit.Assert;
import org.junit.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.AbstractJUnit4SpringContextTests;

import java.util.HashMap;
import java.util.Map;

/**
 * Created with IntelliJ IDEA.
 * User: Administrator
 * Date: 12-8-6
 * Time: 下午5:39
 * To change this template use File | Settings | File Templates.
 */
@ContextConfiguration(locations = { "classpath:spring/test/applicationContext-*.xml" })
public class RestTestCase extends AbstractJUnit4SpringContextTests {

    @Autowired
    private CacheProvider cacheProvider;

    @Test
    public void doPut() throws Exception {
        Map<String, Object> map = new HashMap<String, Object>();
        map.put("a", 1);
        map.put("b", 2);
        map.put("c", "3");

        boolean b = cacheProvider.put("globalCache", "map.key", map);
        Assert.assertTrue(b);
    }

    @Test
    public void doGet() throws Exception {
        Object o = cacheProvider.get("globalCache", "map.key");
        Assert.assertNotNull(o);
        Assert.assertTrue(o instanceof Map);
    }

    @Test
    public void doRemove() throws Exception {
        boolean b = cacheProvider.remove("globalCache", "map.key");
        Assert.assertTrue(b);
    }

    @Test
    public void doGetStatus() throws Exception {
        CacheStatus status = cacheProvider.getStatus("globalCache");
        Assert.assertEquals(CacheStatus.STATUS_ALIVE, status);
    }
}
